<!DOCTYPE html>
<html lang="zh-CN"
      xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org"
      xmlns:layout="http://www.ultraq.net.nz/thymeleaf/layout"
      layout:decorator="model/boardModel">


<body>

<!-- Left side column. contains the logo and sidebar -->
<aside class="main-sidebar" th:fragment="menubar">
    <!-- sidebar: style can be found in sidebar.less -->
    <section class="sidebar">

        <!-- search form -->
        <form action="#" method="get" class="sidebar-form">
            <div class="input-group">
                <input type="text" name="q" class="form-control" placeholder="查询"/>
              <span class="input-group-btn">
                <button type="submit" name="search" id="search-btn" class="btn btn-flat"><i class="fa fa-search"></i>
                </button>
              </span>
            </div>
        </form>
        <!-- /.search form -->
        <!-- sidebar menu: : style can be found in sidebar.less -->
        <ul class="sidebar-menu">
            <li class="header">导航菜单</li>

            <li class="active treeview">
                <a href="/index">
                    <i class="fa fa-dashboard"></i> <span>控制台</span>

                </a>
            </li>

            <div th:each="ppm, menuVs:${session.authUser.authMenu}" th:remove="tag">

                <li class="treeview" th:id="'menu_'+${ppm.id}">

                    <a href="#">
                        <i class="fa fa-dashboard"></i> <span th:text="${ppm.pm.menuName}"></span>
                        <span class="pull-right-container">
                            <i class="fa fa-angle-left pull-right"></i>
                        </span>
                    </a>

                    <ul class="treeview-menu">
                        <div th:each="cm : ${ppm.child}" th:remove="tag">
                            <li th:id="'menu_'+${cm.menuId}">
                                <a th:href="'javascript:gotoHref(\''+${cm.linkUrl}+'\', \''+${ppm.id}+'\', \''+${cm.menuId}+'\')'" >
                                <i class="fa fa-circle-o"></i> <div th:text="${cm.menuName}" th:remove="tag"></div>
                            </a></li>
                        </div>
                    </ul>

                </li>
            </div>


        </ul>


    </section>
    <!-- /.sidebar -->


    <input type="hidden" id="curPmId" th:value="${session.pmId}"/>
    <input type="hidden" id="curMId" th:value="${session.mid}"/>
    <script th:src="@{/plugins/jQuery/jquery-2.2.3.min.js}"></script>
    <script type="text/javascript">
        $(function() {

            var pathname = window.location.pathname;
            var thisHref = $('li[thisHref="'+pathname+'"]');
            var pmId = $(thisHref).attr("pmId");
            var mid = $(thisHref).attr("mId");

            if(pmId==null || mid==null) {
                pmId = $("#curPmId").val();
                mid = $("#curMId").val();
            }
            if(pmId!=null || mid!=null){
                $(("#menu_"+pmId)).addClass("active");
                $(("#menu_"+mid)).addClass("active");
            }
        });

        function gotoHref(href, pm, m) {
            $.post("/setCurrentMenuId", {pmId:pm, mid:m}, function(res) {
                if(res=='1') {window.location.href = href;}
            }, "json");
        }
    </script>

</aside>


</body>
</html>